package com.zuimei.zuimei.fragments;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zuimei.zuimei.R;
import com.zuimei.zuimei.activities.CollectionsDescActivitiy;
import com.zuimei.zuimei.activities.Item2DescActivity;
import com.zuimei.zuimei.adapters.UserCollectionsAdapter;
import com.zuimei.zuimei.adapters.UserRecommandAdapter;
import com.zuimei.zuimei.base.BaseFragment;
import com.zuimei.zuimei.beans.CollectionsBean;
import com.zuimei.zuimei.beans.FindAppItem2Bean;

import java.util.List;

import butterknife.Bind;

/**
 * Created by Jogger on 2017/2/3.
 * 美友主页fragment
 */

public class MeiYouHomeFragment extends BaseFragment {
    @Bind(R.id.rv_content)
    RecyclerView rv_content;
    private UserRecommandAdapter mItem1Adapter;
    private UserCollectionsAdapter mItem2Adapter;
    private LinearLayoutManager mItem1LayoutManager;
    private LinearLayoutManager mItem2LayoutManager;
    private List<FindAppItem2Bean> mRecommandAppList;
    private List<CollectionsBean> mCollectionsList;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_meiyou_home;
    }

    @Override
    public void init() {
        Bundle bundle = getArguments();
        mRecommandAppList = (List<FindAppItem2Bean>) bundle.getSerializable("recommand_list");
        if (mRecommandAppList != null) {
            loadItem1Data();
        }
        mCollectionsList = (List<CollectionsBean>) bundle.getSerializable("collect_list");
        if (mCollectionsList != null) {
            loadItem2Data();
        }
    }

    private void loadItem1Data() {
        mItem1LayoutManager = new LinearLayoutManager(mActivity);
        mItem1Adapter = new UserRecommandAdapter(mActivity);
        rv_content.setLayoutManager(mItem1LayoutManager);
        rv_content.setAdapter(mItem1Adapter);
        //mItem1Adapter.loadHeadData(mUser, mAppList.size());
        mItem1Adapter.loadData(mRecommandAppList);
        mItem1Adapter.setOnItemClickListener(new UserRecommandAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, FindAppItem2Bean app) {
                startNewActivity(Item2DescActivity.class, "app", app);
            }
        });
    }

    private void loadItem2Data() {
        mItem2LayoutManager = new GridLayoutManager(mActivity, 2);
        rv_content.setLayoutManager(mItem2LayoutManager);
        mItem2Adapter = new UserCollectionsAdapter(mActivity);
        rv_content.setAdapter(mItem2Adapter);
        mItem2Adapter.loadData(mCollectionsList);
        mItem2Adapter.setOnItemClickListener(new UserCollectionsAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, CollectionsBean collections) {
                startNewActivity(CollectionsDescActivitiy.class, "collections", collections);
            }
        });
    }

}
